import Vue from 'vue'
import App from './App.vue'
import router from './router'
import lodash from 'lodash'
import axios from 'axios'
import qs from 'qs'
import VueLodash from 'vue-lodash/dist/vue-lodash.min'
import Subtasks from './components/Subtasks.vue'

Vue.use(VueLodash, lodash)
Vue.component('subtasks', Subtasks)

axios.interceptors.request.use(function(config) { // 这里的config包含每次请求的内容
	if (localStorage.access_token) {
		config.headers.Authorization = 'Bearer ' + localStorage.access_token;
		// axios.defaults.headers = {'Authorization': localStorage.access_token};
	}
	return config;
}, function(err) {
	return Promise.reject(err);
})

// http response 拦截器
// axios.interceptors.response.use(
//     response => {
//         return response;
//     },
//     error => {
//         if (error.response) {
//             switch (error.response.status) {
//                 case 401:
//                 // 返回 401 清除token信息并跳转到登录页面
//                 store.commit(types.LOGOUT);
//                 router.replace({
//                     path: 'login',
//                     query: {redirect: router.currentRoute.fullPath}
//                 })
//             }
//         }
//         return Promise.reject(error.response.data)   // 返回接口返回的错误信息
//     })

new Vue({
	el: '#app',
	router,
	template: '<App/>',
	components: {
		App
	}
});
